<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDutySupervisorsTable extends Migration
{
    public function up()
    {
        Schema::create('duty_supervisors', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('ID');
            $table->date('duty_date')->comment('值班日期');
            $table->unsignedBigInteger('supervisor_id')->comment('领导ID');
            $table->string('supervisor_name')->comment('领导姓名');
            $table->string('phone')->nullable()->comment('联系电话');
            $table->string('location')->nullable()->comment('值班地点');
            $table->string('time_range', 100)->nullable()->comment('值班时间段');
            $table->text('remark')->nullable()->comment('备注说明');
            $table->tinyInteger('is_notified')->default(0)->comment('是否已发送微信提醒：0-否 1-是');
            $table->datetime('notified_at')->nullable()->comment('发送提醒时间');

            $table->timestamps();
            $table->softDeletes();

            $table->unique(['duty_date', 'deleted_at'], 'uk_duty_date')->comment('每天只能有一个值班领导');
            $table->index('duty_date', 'idx_duty_date')->comment('值班日期索引');
            $table->index('supervisor_id', 'idx_supervisor_id')->comment('领导ID索引');

            $table->foreign('supervisor_id', 'fk_duty_supervisor_supervisor')->references('id')->on('employees')->onDelete('cascade');
        });

        DB::statement('alter table' . ' ' . config('database.connections.mysql.prefix', '') . 'feedbacks comment "值班领导记录表"');

    }

    public function down()
    {
        Schema::dropIfExists('duty_supervisors');
    }
}

